package com.neusoft.yuejian12.yuejian_12.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian12.yuejian_12.R;
import com.neusoft.yuejian12.yuejian_12.adapter.TrainListAdapter;
import com.neusoft.yuejian12.yuejian_12.javabean.TrainBean;
import com.neusoft.yuejian12.yuejian_12.model.TrainModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class TrainJinjieActivity extends Activity {
    private ImageView left_trainlist;
    private ImageView t_picture;
    private TextView t_name;

    private RecyclerView recyclerView;

    private LayoutInflater mLayoutInflater;


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train_jinjie);
        initView();
        initEvent();
        getTrainData();
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.rv_rumen);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局

        left_trainlist = (ImageView) findViewById(R.id.left_trainlist);

    }

    private void initEvent() {
        //返回上一页
        left_trainlist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


    }


    private void getTrainData() {
        TrainModel trainModel = new TrainModel();
        Call<List<TrainBean>> call = trainModel.getTrainlistc();
        //System.out.print("t_name");
        call.enqueue(new Callback<List<TrainBean>>() {
            @Override
            public void onResponse(Call<List<TrainBean>> call, Response<List<TrainBean>> response) {
                List<TrainBean> data = (List<TrainBean>) response.body();  //获取数据
                //System.out.printf("data");
                recyclerView.setAdapter(new TrainListAdapter(TrainJinjieActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<TrainBean>> call, Throwable t) {

            }
        });

    }
}